package com.kawa.kemanage.controller.api;

import com.kawa.kemanage.service.IncomeService;
import com.kawa.kemanage.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: KAIyo
 * @Date: 2025/6/10 11:27
 * @Version: v1.0.0
 * @Description: TODO
 **/
@RestController
@CrossOrigin
@RequestMapping("/api/income")
public class IncomeController {
    @Autowired
    private IncomeService incomeService;

    @GetMapping("/yearly")
    public Result getYearIncome() {
        int yearIncome = 0;
        try {
            //获取今年的收入
            yearIncome = incomeService.getYearIncome();
            return Result.success(yearIncome);
        }catch (Exception  e){
            e.printStackTrace();
        }
        return Result.error("获取失败");
    }

    @GetMapping("/monthly")
    public Result getMonthIncome() {
        int monthIncome = 0;
        try {
            //获取这个月的收入
            monthIncome = incomeService.getMonthIncome();
            return Result.success(monthIncome);
        }catch (Exception  e){
            e.printStackTrace();
        }
        return Result.error("获取失败");
    }

    @GetMapping("/by-type")
    public Result getByTypeIncome() {
        int yearIncome = 0;
        try {
//            //获取今年的收入
//            yearIncome = incomeService.getByTypeIncome();
            return Result.success(yearIncome);
        }catch (Exception  e){
            e.printStackTrace();
        }
        return Result.error("获取失败");
    }
}
